package ar.com.globallogic.promomr.persistance;

import java.util.List;

import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import ar.com.globallogic.promomr.domain.Document;

@Repository
public interface DocumentRepository extends CrudRepository<Document, String>{
	
	@Query(value="{$and: [" +
					"{'_class': 'ar.com.globallogic.promomr.domain.Document'}, " +
					"{$or:[{$where:'?0==null'},{name: ?0}]}, " +
					"{$or:[{$where:'?1==null'},{description: ?1}]}, " +
					"{$or:[{$where:'?2==null'},{title: ?2}]}, " +
					"{$or:[{$where:'?3==null'},{author: ?3}]}, " +
					"{$or:[{$where:'?4==null'},{amountOfPages: {$gte: ?4}}]}, " +
					"{$or:[{$where:'?5==null'},{amountOfPages: {$lte: ?5}}]} " +
				"]}", 
		   fields="{id : 1}") 
	public List<Document> findByProperties(String name, String description, String title, String author, Long amountOfPagesGreaterThanEquals, Long amountOfPagesLessThanEquals);

}
